import { useState, useEffect } from 'react'
import store from '../../store'

export default function CompB () {
  const [myCount, setMyCount] = useState(store.getState().counter)
  // const [channels, setChannels] = useState(store.getState().channel)

  useEffect(() => {
    // 监听
    const unsubscribe = store.subscribe(() => {
      setMyCount(store.getState().counter)
      // setChannels(store.getState().channel)
    })

    return () => {
      // 解除监听
      unsubscribe()
    }
  }, [])

  return (
    <div>
      CompB
      <p>store value is {myCount}</p>
      {/* <ul>
        {channels.map(item => {
          return <li key={item.id}>{item.name}</li>
        })}
      </ul> */}
    </div>
  )
}
